package com.ed.controller;

import com.ed.domain.Faq;
import com.ed.domain.Hama;
import com.ed.dto.AnswerQDTO;
import com.ed.dto.SubmitDto;
import com.ed.result.Result;
import com.ed.service.IFaqQuestionService;
import com.ed.service.IHamaQuestionService;
import com.ed.vo.QuesVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/Hama")
@CrossOrigin
public class HamaQuestionController {
    @Autowired
    public IHamaQuestionService HamaQuestionService;

    /**
     * 增加Hama题目
     * @param hama
     * @return
     */
    @PostMapping("/AddHama")
    public Result AddFaq(@RequestBody Hama hama) {
        HamaQuestionService.AddHama(hama);
        return Result.success();
    }
    /**
     * 删除Hama题目
     * @param id
     * @return
     */
    @DeleteMapping("DeleteHama")
    public Result DeleteHama(Integer id) {
        HamaQuestionService.DeleteHama(id);
        return Result.success();
    }
    /**
     * 更新Hama题目
     * @param hama
     * @return
     */
    @PutMapping("UpdateHama")
    public Result UpdateHama(@RequestBody Hama hama) {
        HamaQuestionService.UpdateHama(hama);
        return Result.success();
    }
    /**
     * 查询Hama题目和选项
     * @param id
     * @return
     */
    @GetMapping("GetHama")
    public Result<QuesVO> GetHama(Integer id) {
        QuesVO quesVO = HamaQuestionService.getHama(id);
        return Result.success(quesVO);
    }
    /**
     * 查询所有Hama题目和选项
     * @return
     */
    @GetMapping("GetHamas")
    public Result<List<QuesVO>> GetHamas() {
        log.info("查询hamas");
        List<QuesVO> hamas = HamaQuestionService.getHamas();
        return Result.success(hamas);
    }

    /**
     * 计算分数
     * @param submitDto
     * @return
     */
    @PostMapping("/submit")
    public Result submit(@RequestBody SubmitDto submitDto) {
        log.info("提交的题目：{}", submitDto);
        Integer score = HamaQuestionService.calculateScore(submitDto);
        return Result.success(score);
    }
}
